<?php
// Script to display bios written by user

// include the PHP Facebook Client Library
require_once('../facebook/facebook.php');
require_once('db.php');

// application class to fetch application data
include_once('application.php'); 

// display the tabs
include_once('tabs.php');

$facebook = new Facebook(Application::$apiKey, Application::$apiSecret);
$user_id = $facebook->require_login();

// Establish a connection with the DB server and select a DB 
$db = new DB(Application::$mysqlServer, Application::$mysqlUserName, Application::$mysqlPassword);
$db->selectDatabase(Application::$dbName);

// Check if the user is logged on
// .....

// Generate a query to check if a user has written any bios
$whereClause = sprintf("uid=%u", $user_id);
$db->selectQuery(Application::$tableName, "*", $whereClause);

if(!$db->getResult())
{
 echo "You have written no bios as of now";
}
else
{
 // echo "You have " . count($db->getResult()) . " bios";
 echo "<table>";
 while($result = $db->fetchResult()) 
 {
  echo "<tr>";
  // echo "<div class=\"fbbluebox\" style=\"width:500px;\">";
  echo "<td>" . "<fb:profile-pic uid=\"" . $result["friendUid"] . "\" linked=\"true\" />" . "</td>";
  echo "<td valign=\"top\">" . "<fb:name uid=\"" . $result["friendUid"] . "\" />" . "'s bio: " . $result["bioText"] . "</td>";
  // echo "</div>";
  echo "</tr>";
  echo "<br>";
 }
 echo "</table>";

}

?>
